import {RequestParam} from './request-param';

export class RequestBodyDto {
    /**
     * KeyValue值
     * @type {Array}
     */
    formData: RequestParam[] = [];

    /**
     * raw数据
     */
    rawData: string;

    /**
     * raw数据类型
     */
    rawDataType: string;

    get rawJsonData(): JSON {
        if (this.rawData) {
            return JSON.parse(this.rawData);
        } else {
            return JSON.parse('{}');
        }
    }

    public static getDefault(): RequestBodyDto {
        return <RequestBodyDto>{
            formData: <RequestParam[]>[RequestParam.getEmpty()],
            rawData: '',
            rawDataType: 'raw'
        };
    }
}
